/**
 * Created by Lcp on 2018/3/8.
 */
peopleRelationship();
function peopleRelationship(){
    var option = {
        animationDuration: 3000,
        legend: {
            x: 'right',
            y: 'top',
            data:[
                {
                    name: '家人',
                    textStyle: {
                        color: "#cbd9fe"
                    }
                },
                {
                    name: '朋友',
                    textStyle: {
                        color: "#cbd9fe"
                    }
                }
            ]
        },
        series : [
            {
                type:'force',
                name : "人物关系",
                ribbonType: false,
                categories : [
                    {
                        name: '人物'
                    },
                    {
                        name: '家人'
                    },
                    {
                        name:'朋友'
                    }
                ],
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            textStyle: {
                                color: '#cbd9fe'
                            }
                        },
                        nodeStyle : {
                            brushType : 'both',
                            borderColor : 'rgba(255,215,0,0.4)',
                            borderWidth : 1
                        },
                        linkStyle: {
                            type: 'curve'
                        }
                    },
                    emphasis: {
                        label: {
                            show: false
                            // textStyle: null      // 默认使用全局文本样式，详见TEXTSTYLE
                        },
                        nodeStyle : {
                            //r: 30
                        },
                        linkStyle : {}
                    }
                },
                useWorker: false,
                minRadius : 15,
                maxRadius : 25,
                gravity: 1.1,
                scaling: 1.1,
                roam: 'move',
                nodes:[
                    {category:0, name: '任军', value : 10, label: '任军\n（主要）'},
                    {category:1, name: '任小红',value : 2},
                    {category:1, name: '任刚',value : 3},
                    {category:2, name: '刘佳',value : 5},
                    {category:2, name: '张菊',value : 8},
                    {category:2, name: '谢晓楠',value : 9},
                ],
                links : [
                    {source : '任小红', target : '任军', weight : 1, name: '女儿'},
                    {source : '任刚', target : '任军', weight : 2, name: '父亲'},
                    {source : '刘佳', target : '任军', weight : 3, name: '合伙人'},
                    {source : '张菊', target : '任军', weight : 1},
                    {source : '谢晓楠', target : '任军', weight : 6, name: '竞争对手'},
                ]
            }
        ],
        color: ['#9f1154','#4466f4','#24347e','#50123e','#ff106e']
    };
    function focus(param) {
        var data = param.data;
        var links = option.series[0].links;
        var nodes = option.series[0].nodes;
        if (
            data.source !== undefined
            && data.target !== undefined
        ) { //点击的是边
            var sourceNode = nodes.filter(function (n) {return n.name == data.source})[0];
            var targetNode = nodes.filter(function (n) {return n.name == data.target})[0];
            console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
        } else { // 点击的是点
            console.log("选中了" + data.name + '(' + data.value + ')');
        }
    }



    var casePeopleRelationship = echarts.init(document.getElementById('casePeopleRelationshipLeft'));
    casePeopleRelationship.clear();
    casePeopleRelationship.setOption(option);

}
//图片丢失
function nofind(item){
    item.src = '../common/img/nothing.png';
    item.onerror = null;
}